package mumu.android.view;

import mumu.android.R;
import mumu.android.lib.view.ActivityDialog;
import mumu.android.lib.view.NormalDialog;
import mumu.android.lib.view.NormalDialogFragment;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

//在Android 4.0版本以后，官方推荐使用DialogFragment去替换Dialog。
public class dialog1 extends FragmentActivity {
	// ListViewDialog dialog;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(this.getClass().getName());
		setContentView(R.layout.dialog1);
		findViewById(R.id.btn_1).setOnClickListener(onClickListener);
		findViewById(R.id.btn_2).setOnClickListener(onClickListener);
		findViewById(R.id.btn_3).setOnClickListener(onClickListener);
		findViewById(R.id.btn_4).setOnClickListener(onClickListener);
		findViewById(R.id.btn_5).setOnClickListener(onClickListener);
		findViewById(R.id.btn_c).setOnClickListener(onClickListener);

	}

	private void showAlertDialog() {
		AlertDialog dialog= new AlertDialog.Builder(this).setTitle("").setPositiveButton("ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {

			}
		}).setNegativeButton("c", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {

			}
		}).create();
		if(!isFinishing()){
			dialog.show();
		}
	}

	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.btn_1:
				NormalDialog dialog2 = new NormalDialog(dialog1.this);
				dialog2.setCanceledOnTouchOutside(true);
				dialog2.show();
				break;
			case R.id.btn_2:
				NormalDialog dialog1 = new NormalDialog(dialog1.this, R.style.dialog);
				dialog1.setCanceledOnTouchOutside(true);
				dialog1.show();
				break;
			case R.id.btn_3:
				// http://www.cnblogs.com/chrisfang6/articles/2553920.html
				NormalDialog dialog = new NormalDialog(dialog1.this, R.style.dialog);
				dialog.setCanceledOnTouchOutside(true);
				Window dialogWindow = dialog.getWindow();
				WindowManager.LayoutParams lp = dialogWindow.getAttributes();
				dialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
				lp.y = 150;// 垂直坐标把程序标题栏也计算在内.
				lp.x = 150;
				dialogWindow.setAttributes(lp);
				dialog.show();
				break;
			case R.id.btn_5:
				NormalDialog dialog3 = new NormalDialog(dialog1.this, R.style.full_dialog);
				dialog3.setCanceledOnTouchOutside(true);
				dialog3.show();
				break;
			case R.id.btn_4:
				startActivity(new Intent(dialog1.this, ActivityDialog.class));
				break;
			case R.id.btn_c:
				NormalDialogFragment dialogFragment = NormalDialogFragment.getInstance();
				dialogFragment.show(getSupportFragmentManager(), "dialog");
				break;

			default:
				break;
			}
		}
	};

}
